import java.util.ArrayList;

import processing.core.PApplet;

public class ListViewRow extends View {
	private int unselectedColors[] = {206, 203, 250};
	final private int selectedColors[] = {160, 154, 245};
	final private int lineColor[] = {121, 121, 121};
	final private static int disabledColors[] = {205, 205, 205};
	
	private ArrayList<String> captions;
	private int id;
	private ListViewRowDelegate delegate;
	private boolean selected;
	private boolean enabled;
	
	
	/*=============================================================================================
	 * Constructor
	 *-------------------------------------------------------------------------------------------*/
	ListViewRow(float x_, float y_, float w_, float h_, int nCols, MainView p) {
		super(x_, y_, w_, h_, p);
		id = 0;
		delegate = null;
		selected = false;
		enabled = false;
		captions = new ArrayList<String>();
		for( int i=0; i<nCols; i++) captions.add("");
	}
	
	/*=============================================================================================
	 * id get/set
	 *-------------------------------------------------------------------------------------------*/
	void setId( int pIdx) { id = pIdx; }
	int getId() { return id; }
	
	/*=============================================================================================
	 * Delegate set
	 *-------------------------------------------------------------------------------------------*/
	void setDelegate( ListViewRowDelegate pDelegate) { delegate = pDelegate; }
	
	/*=============================================================================================
	 * id get/set
	 *-------------------------------------------------------------------------------------------*/
	boolean contentPressed(float lx, float ly)
	{
		if( delegate != null && enabled) delegate.ListViewRowPressed( this);
		return true;
	}
	
	/*=============================================================================================
	 * captions get/set
	 *-------------------------------------------------------------------------------------------*/
	String getCaption( int col) { return captions.get(col); }
	void setCaption( int col, String c) { captions.set(col, c); }
	
	/*=============================================================================================
	 * 
	 *-------------------------------------------------------------------------------------------*/
	void select() { selected = true; }
	void unSelect() { selected = false; }
	
	/*=============================================================================================
	 * 
	 *-------------------------------------------------------------------------------------------*/
	void disable() { enabled = false; }
	void enable() { enabled = true; }
	
	/*=============================================================================================
	 * 
	 *-------------------------------------------------------------------------------------------*/
	void setColor( int r, int b, int g)
	{
		unselectedColors[0] = r;
		unselectedColors[1] = r;
		unselectedColors[2] = r;
	}
	
	/*=============================================================================================
	 * 
	 *-------------------------------------------------------------------------------------------*/
	void drawContent()
	{
		int nCols = captions.size();
		float colWidth = w/nCols;
		int i;
		
		int color[] = unselectedColors;
		if( selected) color = selectedColors;
		if( !enabled) color = disabledColors;
		parent.fill(color[0],color[1],color[2]);
		parent.strokeWeight(1);
		parent.stroke( lineColor[0], lineColor[1], lineColor[2]);
		for( i=0; i<nCols; i++)
			parent.rect(colWidth*i,0,colWidth,h);
		
		//*
		parent.fill(0);
		parent.textSize(20);
		parent.textAlign(PApplet.CENTER, PApplet.CENTER);
		for( i=0; i<nCols; i++)
			parent.text(captions.get(i), colWidth*i+(colWidth/2), h/2);
		//*/
	}
	
}
